package worldinruin.gui.imp.gameview;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;

import worldinruin.GameDataHandler;
import worldinruin.core.IBuilding;
import worldinruin.core.ITile;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class BuildPanel extends javax.swing.JPanel {
	private JLabel tileIconLabel;
	private JPanel buildingsPanel;
	private ITile tile;
	
	/**
	 * Creates a build panel on the tile.
	 * @param tile Tile position.
	 */
	public BuildPanel(ITile tile) {
		super();
		this.tile = tile;
		initGUI();
		setupGUI();
		
	}
	
	/**
	 * Setup GUI.
	 */
	 private void setupGUI() {
		tileIconLabel.setIcon(GameDataHandler.getInstance().getIconMap().getIcon(tile.getTileType()));
		List<IBuilding> IBuildings = tile.getAvailableBuildings();		
		{
			GridLayout buildingsPanelLayout = new GridLayout(IBuildings.size(), 1);
			buildingsPanelLayout.setColumns(1);
			buildingsPanelLayout.setRows(3);
			buildingsPanelLayout.setVgap(3);
			buildingsPanelLayout.setHgap(3);
		}
		
		for (IBuilding b : IBuildings) {
			BuildingPanel building = new BuildingPanel(b);
			buildingsPanel.add(building);
		}
	}

	 /**
	  * Initiate GUI.
	  */
	private void initGUI() {
		try {
			setPreferredSize(new Dimension(300, 300));
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			
			{
				buildingsPanel = new JPanel();
				FlowLayout buildingsPanelLayout1 = new FlowLayout();
				buildingsPanel.setLayout(buildingsPanelLayout1);
				tileIconLabel = new JLabel();
				buildingsPanel.setBounds(109, 0, 108, 227);
				GroupLayout tileIconLabelLayout = new GroupLayout((JComponent)tileIconLabel);
				tileIconLabel.setLayout(tileIconLabelLayout);
				tileIconLabel.setIcon(null);
				tileIconLabel.setHorizontalAlignment(SwingConstants.CENTER);
				tileIconLabel.setOpaque(true);
				tileIconLabel.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				tileIconLabel.setBounds(12, 71, 85, 84);
				tileIconLabelLayout.setVerticalGroup(tileIconLabelLayout.createParallelGroup());
				tileIconLabelLayout.setHorizontalGroup(tileIconLabelLayout.createParallelGroup());
			}
					thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
						.addContainerGap()
						.addGroup(thisLayout.createParallelGroup()
						    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
						        .addComponent(tileIconLabel, GroupLayout.PREFERRED_SIZE, 84, GroupLayout.PREFERRED_SIZE)
						        .addGap(0, 383, Short.MAX_VALUE))
						    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
						        .addGap(8)
						        .addComponent(buildingsPanel, GroupLayout.PREFERRED_SIZE, 459, GroupLayout.PREFERRED_SIZE)
						        .addGap(0, 0, Short.MAX_VALUE)))
						.addContainerGap(38, 38));
					thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
						.addContainerGap()
						.addComponent(tileIconLabel, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)
						.addGap(24)
						.addComponent(buildingsPanel, GroupLayout.PREFERRED_SIZE, 249, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(104, Short.MAX_VALUE));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
